home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog7.arj / CONTROL2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  5.5 KB  |  220 lines

  1. { control2.pas -- Completed control.pas demonstration. }
  2.  
  3. program Control;
  4.  
  5. uses WinTypes, WinProcs, WObjects, Strings;
  6.  
  7. const
  8.  
  9.   staticOn = 'Select to end program';
  10.   staticOff = 'Click "Ok on" button';
  11.  
  12.   id_CheckBox = 101;
  13.   id_RadioButton = 102;
  14.   id_GroupBox = 103;
  15.   id_Radio1 = 104;
  16.   id_Radio2 = 105;
  17.   id_List = 106;
  18.   id_SingleEd = 107;
  19.   id_MultiEd = 108;
  20.   id_ComboBox = 109;
  21.   id_ScrollBar = 110;
  22.  
  23.  
  24. type
  25.  
  26.   PMultiEd = ^TMultiEd;
  27.   TMultiEd = object(TEdit)
  28.     constructor Init(AParent: PWindowsObject; AnId: Integer;
  29.       ATitle: PChar; X, Y, W, H: Integer; ATextLen: Word);
  30.     procedure DefWndProc(var Msg: TMessage); virtual;
  31.   end;
  32.  
  33.   ControlApplication = object(TApplication)
  34.     procedure InitMainWindow; virtual;
  35.   end;
  36.  
  37.   PControlWindow = ^ControlWindow;
  38.   ControlWindow = object(TWindow)
  39.     OkButton: PButton;
  40.     GroupBox: PGroupBox;
  41.     DefRadio: PRadioButton;
  42.     Static: PStatic;
  43.     ListBox: PListBox;
  44.     SingleEd: PEdit;
  45.     MultiEd: PMultiEd;
  46.     ComboBox: PComboBox;
  47.     ScrollBar: PScrollBar;
  48.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  49.     procedure SetupWindow; virtual;
  50.     procedure IDOk(var Msg: TMessage);
  51.       virtual id_First + id_Ok;
  52.     procedure IDCheckBox(var Msg: TMessage);
  53.       virtual id_First + id_CheckBox;
  54.     procedure IDRadio1(var Msg: TMessage);
  55.       virtual id_First + id_Radio1;
  56.     procedure IDRadio2(var Msg: TMessage);
  57.       virtual id_First + id_Radio2;
  58.     procedure IDList(var Msg: TMessage);
  59.       virtual id_First + id_List;
  60.   end;
  61.  
  62.  
  63. { TMultiEd }
  64.  
  65. {- Construct TMultiEd instances }
  66. constructor TMultiEd.Init(AParent: PWindowsObject; AnId: Integer;
  67.   ATitle: PChar; X, Y, W, H: Integer; ATextLen: Word);
  68. begin
  69.   TEdit.Init(AParent, AnId, ATitle, X, Y, W, H, ATextLen, true);
  70.   Attr.Style := Attr.Style and not (es_AutoHScroll or ws_HScroll)
  71. end;
  72.  
  73. {- Modify DefWndProc to handle Tab and Shift-Tab }
  74. procedure TMultiEd.DefWndProc(var Msg: TMessage);
  75. begin
  76.   if (Msg.Message = wm_KeyDown) and (Msg.WParam = vk_Tab) then
  77.   begin
  78.     if GetKeyState(vk_Shift) < 0 then
  79.       SetFocus(Previous^.HWindow)
  80.     else
  81.       SetFocus(Next^.HWindow);
  82.     Exit
  83.   end;
  84.   TEdit.DefWndProc(Msg)
  85. end;
  86.  
  87. { ControlApplication }
  88.  
  89. {- Initialize ControlApplication object's window }
  90. procedure ControlApplication.InitMainWindow;
  91. begin
  92.   MainWindow := New(PControlWindow, Init(nil, 'Control Demo'))
  93. end;
  94.  
  95.  
  96. { ControlWindow }
  97.  
  98. {- Construct ControlWindow object }
  99. constructor ControlWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  100. var
  101.   AControl: PControl;
  102. begin
  103.   TWindow.Init(AParent, ATitle);
  104.   EnableKBHandler;
  105.   with Attr do
  106.   begin
  107.     X := 0; Y := 0; W := 500; H := 350
  108.   end;
  109.  
  110.   OkButton := New(PButton, Init(@Self, id_Ok, 'Ok',
  111.     390, 280, 80, 30, true));
  112.  
  113.   AControl := New(PCheckBox, Init(@Self, id_CheckBox,
  114.     'Check This Out', 50, 275, 120, 40, nil));
  115.  
  116.   GroupBox := New(PGroupBox, Init(@Self, id_GroupBox,
  117.     'Group', 10, 10, 100, 100));
  118.  
  119.   DefRadio := New(PRadioButton, Init(@Self, id_Radio1,
  120.     'Ok on', 20, 30, 60, 40, GroupBox));
  121.  
  122.   AControl := New(PRadioButton, Init(@Self, id_Radio2,
  123.     'Ok off', 20, 65, 60, 40, GroupBox));
  124.  
  125.   AControl := New(PStatic, Init(@Self, -1,
  126.     'Out of Control', 380, 10, 150, 25, 14));
  127.  
  128.   Static := New(PStatic, Init(@Self, -1,
  129.     staticOn, 325, 250, 200, 25, StrLen(staticOn)));
  130.  
  131.   ListBox := New(PListBox, Init(@Self, id_List,
  132.     150, 20, 150, 160));
  133.  
  134.   SingleEd := New(PEdit, Init(@Self, id_SingleEd,
  135.     'Single-line edit', 150, 195, 150, 25, 128, false));
  136.  
  137.   MultiEd := New(PMultiEd, Init(@Self, id_MultiEd,
  138.     'Multi-line edit', 10, 120, 125, 100, 2048));
  139.  
  140.   ComboBox := New(PComboBox, Init(@Self, id_ComboBox,
  141.     320, 40, 150, 185, 0, 128));
  142.  
  143.   ScrollBar := New(PScrollBar, Init(@Self, id_ScrollBar,
  144.     10, 250, 300, 20, true));
  145.  
  146. end;
  147.  
  148. procedure ControlWindow.SetupWindow;
  149. begin
  150.   TWindow.SetupWindow;
  151.   SetFocus(OkButton^.HWindow);
  152.   DefRadio^.Check;
  153.   ListBox^.AddString('Control Demo');
  154.   ListBox^.AddString('Pascal');
  155.   ListBox^.AddString('C++');
  156.   ListBox^.AddString('BASIC');
  157.   ListBox^.AddString('Batch');
  158.   ComboBox^.AddString('Windows');
  159.   ComboBox^.AddString('DOS');
  160.   ComboBox^.AddString('OS/2');
  161.   ComboBox^.AddString('Unix');
  162. end;
  163.  
  164. {- Respond to selection of Ok button }
  165. procedure ControlWindow.IDOk(var Msg: TMessage);
  166. begin
  167.   CloseWindow
  168. end;
  169.  
  170. {- Respond to checkbox events }
  171. procedure ControlWindow.IDCheckBox(var Msg: TMessage);
  172. begin
  173.   MessageBeep(0)
  174. end;
  175.  
  176. {- Respond to changes in radio button 1 }
  177. procedure ControlWindow.IDRadio1(var Msg: TMessage);
  178. begin
  179.   OkButton^.Show(sw_Show);
  180.   Static^.SetText(staticOn);
  181. end;
  182.  
  183. {- Respond to selecting radio button 2 }
  184. procedure ControlWindow.IDRadio2(var Msg: TMessage);
  185. begin
  186.   OkButton^.Show(sw_Hide);
  187.   Static^.SetText(staticOff);
  188. end;
  189.  
  190. {- Respond to list box notification events }
  191. procedure ControlWindow.IDList(var Msg: TMessage);
  192. var
  193.   Len: Integer;
  194.   Buffer: array[0 .. 24] of Char;
  195. begin
  196.   if Msg.LParamHi = lbn_SelChange then
  197.   begin
  198.     Len := ListBox^.GetSelString(Buffer, Sizeof(Buffer) - 1);
  199.     if Len > 0 then
  200.       SetWindowText(HWindow, Buffer)
  201.   end
  202. end;
  203.  
  204. var
  205.  
  206.   ControlApp: ControlApplication;
  207.  
  208. begin
  209.   ControlApp.Init('ControlApp');
  210.   ControlApp.Run;
  211.   ControlApp.Done
  212. end.
  213.  
  214.  
  215. {--------------------------------------------------------------
  216.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  217.   Revision 1.00    Date: 5/9/1991
  218. ---------------------------------------------------------------}
  219.  
  220.